package com.monise.dao.DAO;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.monise.dao.BaseDao.GenericDao;
import com.monise.model.Animal;
import com.monise.model.Cliente;
import com.monise.model.ClienteAnimal;

public class ClienteAnimalDAO extends GenericDao<ClienteAnimal>{
	
	public List<ClienteAnimal> getClienteAnimal(Cliente cliente){
		EntityManager manager = getEntityManager();
		
		manager.getTransaction().begin();
		Query query = manager.createQuery("SELECT a from ClienteAnimal a where a.cliente.pkCliente=:cliente");
		query.setParameter("cliente",cliente.getPkCliente());

	    @SuppressWarnings("unchecked")
		List<ClienteAnimal> clienteAnimal = query.getResultList();

		manager.getTransaction().commit();
		manager.close();

		return clienteAnimal;
	}
	
	public ClienteAnimal getClienteAnimal(Animal animal){
		EntityManager manager = getEntityManager();
		
		manager.getTransaction().begin();
        Query query = manager.createQuery("SELECT a from ClienteAnimal a where a.animal.pkAnimal=:animal");
		query.setParameter("animal",animal.getPkAnimal());

	    ClienteAnimal clienteAnimal = (ClienteAnimal) query.getSingleResult();

		manager.getTransaction().commit();
		manager.close();

		return clienteAnimal;
	}

}
